package com.example.node;

import com.example.ProcessFlowContext;
import com.example.domain.Order;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

@LiteflowComponent(id = "confirmShippingCost", name = "确认运费节点")
@Component
@Slf4j
public class ConfirmShippingCostNode extends NodeComponent {
    @Override
    public void process() throws Exception {
        ProcessFlowContext context = this.getContextBean(ProcessFlowContext.class);
        Order order = context.getOrder();
        if (order.getAmount().intValue() >= 68) {
            order.setShippingCost(BigDecimal.valueOf(0));
        } else {
            order.setShippingCost(BigDecimal.valueOf(10));
        }
        log.info("运费已确认：{}元", order.getShippingCost());
    }
}
